<!DOCTYPE html>
<%@page import="cn.school.service.GradeService"%>
<%@page import="cn.school.service.StudentService"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="cn.school.entity.*,java.util.*,service.*,java.text.*"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>修改学生信息</title>
<style type="text/css">
form {
	border: 1px solid black;
}
</style>
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
</head>
<body>
	<%@include file="checkLogin.jsp"%>
	<%
		long stuno = Long.parseLong(request.getParameter("stuno"));
		StudentService service = new StudentService();
		Student s = service.get(stuno);
		if (s == null) {
			out.print("<script>alert('学生不存在');history.back();</script>");
			return;
		}
	%>
	<form action="doUpdatestudent.jsp" method="post" enctype="multipart/form-data">
		<p>
			<label>学号:</label> <input type="text" name="stuno"
				readonly="readonly"  value="<%=s.getStuno()%>" />
		</p>
		<p>
			<label>姓名:</label> <input type="text" name="sname"
				required="required" value="<%=s.getSname()%>" />
		</p>
		<p>
			<label>性别:</label> <input type="radio" required name="sex" value="男" />男
			<input type="radio" required name="sex" value="女" />女 <input
				type="radio" required name="sex" value="妖" /> 妖

			<%-- 男：<input type="radio" required name="sex" value="男" <%=s.getSex().equals("男")?"checked":""%> />
	女：<input type="radio" required name="sex" value="女" <%=s.getSex().equals("女")?"checked":""%>  />
	妖：<input type="radio" required name="sex" value="妖" <%=s.getSex().equals("妖")?"checked":"" %> />	 --%>
		</p>
		<p>
			<label>电话:</label> <input type="text" name="telephone"
				required="required" value="<%=s.getTelephone()%>" />
		</p>
		<p>
			<label>qq:</label> <input type="text" name="qq"
				value="<%=s.getQq()%>" />
		</p>
		<p>
			<label>微信:</label> <input type="text" name="wechat"
				value="<%=s.getWechat()%>" />
		</p>

		<p>
			<label>年级:</label>
			<%
				GradeService g = new GradeService();
				List<Grade> list2 = g.findALL();
			%>
			<select name="gradeid">

				<%
					for (Grade gr : list2) {
				%>

				<option value="<%=gr.getId()%>"<%-- <%
				if(gr.getId()==s.getGradeid()){
					out.print("selected='selected'");
				} %>--%>
				><%=gr.getGname()%></option>

				<%
					}
				%>
			</select>


		</p>
		<p>
			<label>入学日期:</label> <input type="text" name="enterdate"
				value="<%SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			if (s.getEnterdate() != null) {
				out.print(sdf.format(s.getEnterdate()));
			}%>" />
		</p>
		<p>
			<label>来自哪个城市:</label> <input type="text" name="fromcity"
				required="required" value="<%=s.getFromcity()%>" />
		</p>
		<p>
			<label>生日:</label> <input type="text" name="birthday"
				required="required"
				value="<%SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
			if (s.getBirthday() != null)
				//out.print(s.getBirthday());
				out.print(sdf1.format(s.getBirthday()));%>" />
		</p>
		<p>
			<label>地址:</label> <input type="text" name="address"
				value="<%=s.getAddress()%>" />
		</p>
		<p>
			<label>密码:</label> <input type="text" name="pass" required="required"
				value="<%=s.getPass()%>" />
		</p>
		<p>
			<label>身份证照片</label> <input type="file" name="idcardpic"
				placeholder="更换图片" /> <img src="img/<%=s.getIdcardpic()%>"
				alt="没有图片" height="200px" width="200px" />
		</p>
		<p>
			<button type="submit" class="page-btn" name="save">确认</button>
		</p>
	</form>

</body>
<script>
 $(function(){
	  $(":radio[name=sex][value='<%=s.getSex()%>']").prop("checked",true);
	  $("select[name=gradeid]").val('<%=s.getGradeid()%>');
	});
</script>
</html>
